#include <dao.h>
#include <btBulletDynamicsCommon.h>

#include "btVector3.h"

static void construct(DaoContext *ctx, DValue *p[], int N) {
    btVector3* ptr = new btVector3(p[0]->v.f, p[1]->v.f, p[2]->v.f);

    DaoCData *cdata = DaoContext_PutCData(ctx, ptr, &btVector3Typer);
};

static void destruct(void *self) {
    delete (btVector3*) self;
}

static void getX(DaoContext *ctx, DValue *p[], int N) {
    btVector3* ptr = (btVector3*) DaoCData_GetData(p[0]->v.cdata);

    DaoContext_PutFloat(ctx, ptr->getX());
}

static void getY(DaoContext *ctx, DValue *p[], int N) {
    btVector3* ptr = (btVector3*) DaoCData_GetData(p[0]->v.cdata);

    DaoContext_PutFloat(ctx, ptr->getY());
}

static void getZ(DaoContext *ctx, DValue *p[], int N) {
    btVector3* ptr = (btVector3*) DaoCData_GetData(p[0]->v.cdata);

    DaoContext_PutFloat(ctx, ptr->getZ());
}

static DaoFuncItem meth[] = {
    { construct,	"btVector3(x:float, y:float, z:float)" },

    { getX,		"getX(self:btVector3) => float" },
    { getY,		"getY(self:btVector3) => float" },
    { getZ,		"getZ(self:btVector3) => float" },

    { getX,		".x(self:btVector3) => float" },
    { getY,		".y(self:btVector3) => float" },
    { getZ,		".z(self:btVector3) => float" },

    { NULL, NULL }
};

DaoTypeBase btVector3Typer = {
    "btVector3",
    NULL,
    NULL,               /* constant */
    meth,       	/* methods */
    { NULL },     	/* parent type */
    { NULL },
    destruct,
    NULL                /* free by free() */
};
